{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e8c8ce1e",
   "metadata": {},
   "source": [
    "*本学习记录人：陈依玟\n",
    "\n",
    "*学习时间：2021-11-23\n",
    "\n",
    "*week13\n",
    "\n",
    "*参考的文档：\n",
    "\n",
    "> 1. [Python的官方文档]（https://docs.python.org/3/）\n",
    "> 2. [许老师的博客]（https://www.cnblogs.com/xuzhichao/p/11407192.html）\n",
    "> 3.[pyecharts的官方文档] (https://pyecharts.org/#/)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ead15d44",
   "metadata": {},
   "source": [
    "## 1.列表实践之购物车\n",
    "\n",
    "\n",
    "---\n",
    "架构：\n",
    "```\n",
    "用户输入价格？\n",
    "商品列表 = [\n",
    "    [商品1名称，价格，编号？]\n",
    "    [商品2名称，价格，编号？]\n",
    "]\n",
    "\n",
    "打印\n",
    "---------\n",
    "商品1 编号1 价格1\n",
    "商品2 编号2 价格2\n",
    "商品3 编号3 价格3\n",
    "\n",
    "\n",
    "用户输入编号购买\n",
    "\n",
    "判断1 商品是否存在？\n",
    "\n",
    "判断2 用户余额是否够？\n",
    "\n",
    "结束:用户输入“退出”推出购买(while)\n",
    "    打印用户的购买信息，打印余额\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "af8413d2",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-18-5bbce578515f>, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-18-5bbce578515f>\"\u001b[1;36m, line \u001b[1;32m12\u001b[0m\n\u001b[1;33m    user_goodscart =\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 商品信息： 列表数据\n",
    "goods_list[int_(choice)]# 用户输入之后选择的商品信息\n",
    "goods_list = [\n",
    "    ['珍珠奶茶',6],\n",
    "    ['柠檬茶大杯',4],\n",
    "    ['奶盖四季柠檬茶',8],\n",
    "    ['杨枝甘露',7],\n",
    "    ['圣代',6]\n",
    "]\n",
    "\n",
    "# 用户购物车商品信息：列表数据\n",
    "user_goodscart =\n",
    "\n",
    "# 用户输入\n",
    "Alipay = input('请输入您的账户余额:')\n",
    "\n",
    "# 打印商品信息\n",
    "#-------\n",
    "#商品编号： %s ,商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s ,商品名称：%s, 商品价格：%s\n",
    "print(\"------商品列表-----\")\n",
    "print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(0,goods_list[0][0],goods_list[0][1]))\n",
    "print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(1,goods_list[1][0],goods_list[1][1]))\n",
    "print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(2,goods_list[2][0],goods_list[2][1]))\n",
    "print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(3,goods_list[3][0],goods_list[3][1]))\n",
    "print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(3,goods_list[3][0],goods_list[3][1])) \n",
    "while True:\n",
    "    print(\"----商品列表-----\")\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1])\n",
    "    \n",
    "              \n",
    "    choice = input(\"请输入你要购买的商品编号(输入'q'退出购买):\") #1.输入编号数字 2.输入\"q\" 3.输入的啥也不是！\n",
    "    if choice.isdigit() \n",
    "    # 1.输入编号数字 数值应该在 商品列表范围以内\n",
    "    # 判断1： Alipay  ? goods_[chpice][1](商品价格)\n",
    "        if Alipay >= goods_list[int(choice)][1]：\n",
    "              #1.Alipay重新赋值\n",
    "            Alipay = Alipay - goods_list[int(choice)][1] #扣钱\n",
    "            print(\"你点的【%s】已经购买成功，请等待~，你的余额还有【%s】元\"%s(goods_list[int(choice)][0]),Alipay))\n",
    "        else:\n",
    "            print(\"你的钱包不够啊，换种支付方式吧~\")\n",
    "    elif choice == \"q\":\n",
    "        # 2.输入\"q\"\n",
    "        print(\"-----购物车------\")\n",
    "        print(\"你的购物车为\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "23001312",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(goods_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7c5d718a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-3-a903c13aa4d0>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-3-a903c13aa4d0>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    for i in range (len(goods_list))：\u001b[0m\n\u001b[1;37m                                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "\n",
    "for i in range (len(goods_list))：\n",
    "    print(\"商品编号： %s ,商品名称：%s, 商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1])\n",
    "choice = input(\"请输入你要购买的商品编号\")\n",
    "# 判断1： Alipay  ? goods_[chpice][1](商品价格)\n",
    "if Alipay >= goods_list[int(choice)][1]：\n",
    "          #1.Alipay重新赋值\n",
    "    Alipay = Alipay - goods_list[int(choice)][1] #扣钱\n",
    "    print(\"你点的【%s】已经购买成功，请等待~，你的余额还有【%s】元\"%s(goods_list[int(choice)][0]),Alipay))\n",
    "else:\n",
    "    print(\"你的钱包不够啊，换种支付方式吧~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3d5d584c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你要购买的商品编号6\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-4-fd7fd69b5361>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mchoice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你要购买的商品编号\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# input默认是字符串\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgoods_list\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mchoice\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "choice = input(\"请输入你要购买的商品编号\") # input默认是字符串\n",
    "print(goods_list[int(choice)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f5880b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4288bda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账户余额：13\n",
      "-----------商品列表----------\n",
      "商品编号：0 ,商品名称：珍珠奶茶, 商品价格：6\n",
      "商品编号：1 ,商品名称：奶盖四季柠檬茶, 商品价格：8\n",
      "商品编号：2 ,商品名称：杨枝甘露, 商品价格：7\n",
      "商品编号：3 ,商品名称：圣代, 商品价格：6\n",
      "商品编号：4 ,商品名称：多肉葡萄, 商品价格：10\n",
      "请输入你要购买的商品编号（输入‘q’退出购买）：4\n",
      "\n",
      "你点的【多肉葡萄】已经购买成功，请等候~，您的余额还有【3】元\n",
      "\n",
      "-----------商品列表----------\n",
      "商品编号：0 ,商品名称：珍珠奶茶, 商品价格：6\n",
      "商品编号：1 ,商品名称：奶盖四季柠檬茶, 商品价格：8\n",
      "商品编号：2 ,商品名称：杨枝甘露, 商品价格：7\n",
      "商品编号：3 ,商品名称：圣代, 商品价格：6\n",
      "商品编号：4 ,商品名称：多肉葡萄, 商品价格：10\n",
      "请输入你要购买的商品编号（输入‘q’退出购买）：0\n",
      "\n",
      "你的钱包不够啊，换种方式支付吧~\n",
      "\n",
      "-----------商品列表----------\n",
      "商品编号：0 ,商品名称：珍珠奶茶, 商品价格：6\n",
      "商品编号：1 ,商品名称：奶盖四季柠檬茶, 商品价格：8\n",
      "商品编号：2 ,商品名称：杨枝甘露, 商品价格：7\n",
      "商品编号：3 ,商品名称：圣代, 商品价格：6\n",
      "商品编号：4 ,商品名称：多肉葡萄, 商品价格：10\n",
      "请输入你要购买的商品编号（输入‘q’退出购买）：0\n",
      "\n",
      "你的钱包不够啊，换种方式支付吧~\n",
      "\n",
      "-----------商品列表----------\n",
      "商品编号：0 ,商品名称：珍珠奶茶, 商品价格：6\n",
      "商品编号：1 ,商品名称：奶盖四季柠檬茶, 商品价格：8\n",
      "商品编号：2 ,商品名称：杨枝甘露, 商品价格：7\n",
      "商品编号：3 ,商品名称：圣代, 商品价格：6\n",
      "商品编号：4 ,商品名称：多肉葡萄, 商品价格：10\n"
     ]
    }
   ],
   "source": [
    "# 商品信息：列表数据\n",
    "# goods_list[int(choice)] 用户输入之后选择的商品信息\n",
    "goods_list = [\n",
    "    ['珍珠奶茶',6],\n",
    "    ['奶盖四季柠檬茶',8],\n",
    "    ['杨枝甘露',7],\n",
    "    ['圣代',6],\n",
    "    ['多肉葡萄',10]\n",
    "]\n",
    "\n",
    "# 用户购物车信息：列表数据\n",
    "user_shopping_cart = []\n",
    "\n",
    "# 用户输入\n",
    "Alipay = int(input('请输入您的账户余额：'))\n",
    "\n",
    "# 打印商品信息\n",
    "# ---------\n",
    "# 商品编号：%s ,商品名称：%s, 商品价格：%s\n",
    "# 商品编号：%s ,商品名称：%s, 商品价格：%s\n",
    "\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(0,goods_list[0][0],goods_list[0][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(1,goods_list[1][0],goods_list[1][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(2,goods_list[2][0],goods_list[2][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(3,goods_list[3][0],goods_list[3][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(4,goods_list[4][0],goods_list[4][1]))\n",
    "while True: # 考虑什么时候退出\n",
    "    print(\"-----------商品列表----------\")\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "\n",
    "    choice = input(\"请输入你要购买的商品编号（输入‘q’退出购买）：\") # 1. 输入编号数字  2. 输入“q”3. 输入的啥也不是！\n",
    "    if choice.isdigit():\n",
    "        if int(choice)>=0 and int(choice)<len(goods_list):\n",
    "        # 一、数字 在 列表范围内\n",
    "            # 1. 输入编号数字 数值应该在 商品列表范围以内 \n",
    "            # 判断1 ： Alipay  VS  goods_list[choice][1]（商品价格）   goods_list[int(choice)] (用户输入之后选择的商品信息)\n",
    "            if Alipay >= goods_list[int(choice)][1]:\n",
    "                # 1. Alipay重新赋值\n",
    "                Alipay = Alipay - goods_list[int(choice)][1] # 扣钱\n",
    "                print(\"\\n你点的【%s】已经购买成功，请等候~，您的余额还有【%s】元\\n\"%(goods_list[int(choice)][0],Alipay))\n",
    "                user_shopping_cart.append(goods_list[int(choice)] ) # 增加用户选择的商品信息\n",
    "            else:\n",
    "                print(\"\\n你的钱包不够啊，换种方式支付吧~\\n\")\n",
    "        else:\n",
    "        # 二、数字 不在 列表范围内\n",
    "            print(\"您输入的商品不存在，请输入正确的商品编码（输入‘q’退出购买）：\")\n",
    "    elif choice == \"q\":\n",
    "        # 2. 输入“q”\n",
    "        print(\"-----------购物车----------\")\n",
    "        print(\"您的购物车为【%s】,您的余额还有【%s】\"%(user_shopping_cart,Alipay))\n",
    "        break    \n",
    "    else:\n",
    "        # 3.  输入的啥也不是！不符合要求\n",
    "        print(\"**您输入的内容不符合要求，请检查重新输入！**\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea31c929",
   "metadata": {},
   "source": [
    "## 2.请同学们尝试完成实践（二）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "582a03c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding:utf-8 -*-\n",
    "# Author:Zhichao\n",
    "#猜数字（0-100）\n",
    "\n",
    "\n",
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "\n",
    "if hide_card <100 and hide_card >0:\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit = int(input(\"guess_digit:\"))\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes, you got it.\")\n",
    "                break\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"think smaller...\")\n",
    "            else:\n",
    "                print(\"think bigger...\")\n",
    "            count +=1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对,你个笨蛋!\")\n",
    "            print(\"正确答案：%s\"%(hide_card))\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间。不要耍赖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2afc1b15",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
